import { getProject, getProjectWorker } from '../../../api/app'
import { exportBillGsc } from '../../api/insurance'
import { openDocument } from '../../../utils/util'
const app = getApp()
Page({

    /**
   * 页面的初始数据
   */
    data: {
        id: '',
        serveCompanyName: '',
        wesureTypeName: '',
        billAmount: '',
        createUserName: '',
        insureTimeGSC: '',
        expiredTimeGSC: '',
        count: '',
        workers: [],
        insurRate:''
    },

    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function (options) {
        this.setData({
            id: options.id
        })
        getProject({
            id: options.id
        }).then(res=>{
            console.log(res)
            this.setData({
                serveCompanyName: res.serveCompanyName,
                wesureTypeName: res.wesureTypeName,
                billAmount: res.billAmount,
                createUserName: res.createUserName,
                insureTimeGSC: res.insureTimeGSC,
                expiredTimeGSC: res.expiredTimeGSC,
                insurRate:res.insurRate
            })
        })
        getProjectWorker({
            projectId: options.id
        }).then(res=>{
            console.log(res)
            this.setData({
                count: res.count,
                workers: res.list
            })
        })
    },
    // 导出名单
    exportWorkerList() {
        exportBillGsc({
            projectId: this.data.id
        }).then(res => {
            const url = app.globalData.baseUrl + '/common/download?fileName=' + res +
                '&delete=false'
            console.log(url)
            if (wx.canIUse('openDocument')) {
                const projectName = this.data.serveCompanyName.replace(/\//g, '.') + this.data.id +'.xlsx'
                openDocument(url, projectName).then(() => {}, () => {
                    this.setData({
                        copyLinkStatus: true,
                        copyLinkContent: url
                    })
                })
            } else {
                this.setData({
                    copyLinkStatus: true,
                    copyLinkContent: url
                })
            }
        })
    },
})